package com.src.myapplication.ui.view.fragmentzhibo;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.src.myapplication.R;
import com.src.myapplication.base.BaseFragmentSwp;
import com.src.myapplication.bean.FuJinben;
import com.src.myapplication.config.UrlConfig;
import com.src.myapplication.utils.UIManager;
import com.src.myapplication.widget.CommonAdapter;
import com.src.myapplication.widget.PlayActivity;
import com.src.myapplication.widget.base.ViewHolder;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class FuJin extends BaseFragmentSwp {


    public RecyclerView mRcv;
    @Override
    protected void initData(View view) {
        mRcv= (RecyclerView) view.findViewById(R.id.rcv);
    }


    @Override
    public int getLayoutId() {
        return R.layout.fragment_fujin;
    }

    @Override
    public int getid() {
        return R.id.sw;
    }

    @Override
    public String geturl() {
        return UrlConfig.ZhiBo.ZHIBO_FUJIN_TITLE;
    }


    @Override
    public Class<? extends Object> getben() {
        return FuJinben.class;
    }

    @Override
    public void addList(String string) {
        if (string!=null){
            Gson gson=new Gson();
            List<FuJinben> list=new ArrayList<>();
            Type type=new TypeToken<ArrayList<FuJinben>>(){}.getType();
            list= gson.fromJson(string,type);
            CommonAdapter<FuJinben> adapter1=new CommonAdapter<FuJinben>(getContext(),R.layout.fragment_xinren_list,list) {
                @Override
                protected void convert(ViewHolder holder, FuJinben fuJinben, int position) {
                    int users = fuJinben.getUsers();//观看人数
                    String nickname = fuJinben.getUser().getNickname();//名称
                    final String mingcheng = fuJinben.getCover();//neir
                    TextView name = holder.getView(R.id.name);
                    TextView bott = holder.getView(R.id.bott);
                    ImageView neirong = holder.getView(R.id.neirong);
                    name.setText(String.valueOf(users));
                    bott.setText(nickname);
                    Glide.with(getContext()).load(mingcheng).into(neirong);
                    String rtmp = fuJinben.getRtmp();
                    int uid = fuJinben.getUid();
                    String avatar = fuJinben.getUser().getAvatar();
                    final String[] data=new String[]{String.valueOf(uid),nickname,avatar,rtmp};
                    neirong.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            UIManager.startActivity(getContext(), PlayActivity.class,data);
                        }
                    });

                }
            };
//            BaseRecyclerAdapter adapter = new BaseRecyclerAdapter<>(adapter1);
//            View inflate = LayoutInflater.from(getContext()).inflate(R.layout.header, null);
//            mBanner = (Banner) inflate.findViewById(R.id.banner);
//            mBanner.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,200));
//            adapter.addHeader(mBanner);
//            String[] images =new String[]{UrlConfig.ZhiBo.ZHIBO_XINREN_TITLE};
//            mBanner.setImages(Arrays.asList(images)).setDelayTime(5000).setImageLoader(new GlideImageLoader()).start();
            StaggeredGridLayoutManager manager=new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);

            mRcv.setLayoutManager(manager);
            mRcv.setAdapter(adapter1);
        }
    }


    @Override
    public void showLoadFailMsg() {

    }
}